package loader.core.load
{
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.utils.ByteArray;
	
	import loader.core.BaseServer;
	import loader.core.LoadFile;
	/**
	 * 资源解析器 (不包括文本文件)
	 * @author chenanbao
	 * 
	 */	
	public class ResParse extends BaseLoader
	{
		private var loader:Loader;
		
		public function ResParse(server:BaseServer)
		{
			super(server);
			loader = new Loader();
		}
		
		public override function  initListener():void{
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
		}
		
		public override function  removeListener():void{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeHandler);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
		}
		
		public override function loadFile(file:LoadFile):void{
			super.loadFile(file);			
			this.loader.loadBytes(server.decode(this.file.data as ByteArray));
		}
		
		public override function completeHandler(event:Event):void{
			this.file.data = event.target.content;
			loader.unloadAndStop(true);//用profile查看内存时注释掉
			super.completeHandler(event);
		}
			
		
	}
}